/**
 * 
 */
package com.novartis.nims.trialsubmitter;

/**
 * @author snydejo1
 *
 */
final class SubmissionKey {
	
	private final String mCompositeKey; //cache the concatenation of individual keys
	
	private final String mTrialKey;
	private final String mSubjectKey;
	private final String mVisitKey;
	private final String mVisitRepeatKey;
	private final String mScanKey;
	private final String mScanRepeatKey;
	private final String mFileKey;
	
	private String mVisitNumber;

	SubmissionKey(String trial,
				  String subject,
				  String visit,
				  String visitRepeat,
				  String scan,
				  String scanRepeat,
				  String fileKey) {
		
		mTrialKey = trial;
		mSubjectKey = subject;
		mVisitKey = visit;
		mVisitRepeatKey = visitRepeat;
		mScanKey = scan;
		mScanRepeatKey = scanRepeat;
		mFileKey = fileKey;
		
		mCompositeKey = mTrialKey +
						mSubjectKey +
						mVisitKey +
						mVisitRepeatKey +
						mScanKey +
						mScanRepeatKey +
						mFileKey;
	}

	SubmissionKey(String trial,
				  String subject,
				  String visit,
				  String visitRepeat,
				  String scan,
				  String scanRepeat) {
		this(trial, subject, visit, visitRepeat, scan, scanRepeat, "dummy");
	}

	/**
	 * Compares this SubmissionKey to the specified object.  The result is {@code
     * true} if and only if the argument is not {@code null} and is a {@code
     * SubmissionKey} object that represents the same set of keys as this
     * object.
     *
     * @param  anObject
     *          - The object to compare this {@code SubmissionKey} against
     *
     * @return  {@code true} if the given object represents a {@code SubmissionKey}
     *          equivalent to this key, {@code false} otherwise
     *
     * @see java.lang.Object#equals(java.lang.Object)
     * @see java.lang.String#equals(java.lang.Object)
	 */
	public final boolean equals(Object anObject) {
		if (this == anObject) {
			return true;
		}
		
		if (anObject instanceof SubmissionKey) {
			return mCompositeKey.equals(((SubmissionKey) anObject).mCompositeKey);
		}

		return false;
	}

	/**
	 * <p>Get a hash value which represents the {@code SubmissionKey}.</p>
	 *
	 * <p>This method is overridden so as to comply with the contract that two
	 * keys that return true for equals() will return the same value for hashCode().
	 * This makes the object safe to use in hashed collections.</p>
     *
     * @return  a hash code value representing the key.
     * 
	 * @see java.lang.Object#hashCode()
	 */
	public final int hashCode() {
		return mCompositeKey.hashCode();
	}

	public String getTrialKey() {
		return mTrialKey;
	}

	public String getSubjectKey() {
		return mSubjectKey;
	}

	public String getVisitRepeatKey() {
		return mVisitRepeatKey;
	}

	public String getVisitKey() {
		return mVisitKey;
	}

	public String getScanRepeatKey() {
		return mScanRepeatKey;
	}

	public String getScanKey() {
		return mScanKey;
	}

	public String getFileKey() {
		return mFileKey;
	}

	public String getVisitNumber() {
		return mVisitNumber;
	}

	public void setVisitNumber(String visitNumber) {
		mVisitNumber = visitNumber;
	}
}
